#include "libcell_wrapper.h"


#define _ReadOff_   LibCell_ReadOff_
#define _ReadCell_  LibCell_ReadCell_
#define _WriteCell_ LibCell_WriteCell_
#define _ReadArray_ LibCell_ReadArray_

void test ()
{
    Node* node=NULL;
    int *v=(int*)malloc(sizeof(int));
    *v=99;
    node=node_overlying(node,v);


    printf("test teste:%d\n",*((int*)(node->value)));
    printf("fdsfsdfddsdsdliboooooooooo\n");
}


int libcell_get_pcell_id(void * c)
{
    return ((struct Cell*)c)->id;
}

int libcell_get_pvertex_id(void * v)
{
    return ((struct Vertex*)v)->id;
}

int libcell_get_phalfface_id(void * hf)
{
    return ((struct HalfFace*)hf)->id;
}

int libcell_get_pface_id(void* f)
{
    return ((struct Face*)f)->id;
}


void* libcell_get_int_tree_begin(void* tree1)
{
    Int_RB_Tree* tree=(Int_RB_Tree*)tree1;
    Int_RB_Tree_Trav trav=tree->begin(tree);
    if(trav.it==NULL)
    {
        tree->prop=NULL;
        return NULL; 
    }
    else
    {
        Int_RB_Tree_Trav *re=(Int_RB_Tree_Trav*)malloc(sizeof(Int_RB_Tree_Trav));
        *re=trav;
        tree->prop=re;
        return trav.it; 
    } 
    return NULL;
}

void* libcell_get_int_tree_next(void* tree1)
{
    Int_RB_Tree * tree=(Int_RB_Tree*)tree1;
    if(tree->prop==NULL)
    {
        return NULL;
    } 
    Int_RB_Tree_Trav *trav=(Int_RB_Tree_Trav*)(tree->prop);
    trav->next(trav);
    if(trav->it==NULL)
    {
        free(trav);
        tree->prop=NULL;
        return NULL;
    }
    else
    {
        return trav->it;
    } 
}


int libcell_get_int_tree_node_key(void* node)
{
    Int_RB_Tree_Node* n=(Int_RB_Tree_Node*)node; 
    return n->key;  
}

void* libcell_get_int_tree_node_value(void* node)
{
    Int_RB_Tree_Node* n=(Int_RB_Tree_Node*)node; 
 
    return n->data;  
}
Mesh* libcell_read_cell_(char *filename)
{
    Mesh *re=(Mesh*)malloc(sizeof(Mesh));
    Mesh_init(re);
    _ReadCell_ (re,filename);
    printf("numv:%d\n",re->num_v(re));
    return re;

}
Int_RB_Tree* libcell_get_mesh_vertices(Mesh*m)
{
    return m->vertices;
}
// Mesh* libcell_read_array_ (double**V,int**F,int **C,int*num,int back_dim,int manifold_dim)
// {
//     Mesh*re=(Mesh*)malloc(sizeof(Mesh));
//     Mesh_init(re);
//     _ReadArray_(re,V,F,C,num,back_dim,manifold_dim);
//     return re; 
// }
void libcell_int_rb_tree_free(void *tree1)
{
    Int_RB_Tree* tree=(Int_RB_Tree*)tree1;

    int_rb_tree_free(tree);
}